﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SmartCity.ProcessEngine.API.ErrorCode;
using SmartCity.ProcessEngine.API.Read.Applications.Commands;
using SmartCity.ProcessEngine.API.Read.Applications.Commands.Nodes;
using SmartCity.ProcessEngine.API.Read.DTOS;

namespace SmartCity.ProcessEngine.API.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ManagementController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public ManagementController(ILogger<ManagementController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 表单分类列表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<APIPaging<FormTypeDTO>>> TypeShow([FromQuery] FormTypeQueryCommand command)
        {
            try
            {
                logger.LogInformation("表单分类列表成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("表单分类列表失败进入异常"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 行业列表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<IndustyDTO>>> IndustyShow()
        {
            IndustyQueryCommand command=new IndustyQueryCommand();
            return mediator.Send(command);
        }
        /// <summary>
        /// 表单列表
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<FormDTO>>> FormShow([FromQuery] FormQueryCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 表单分类方法
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<FormTypeDTO>>> GetFormType([FromQuery] FormTypeCascaderQueryCommand command)
        {
            try
            {

                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// 节点列表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<NodeDTO>>> NodeShow([FromQuery] NodeQueryCommand command)
        {
            try
            {
                logger.LogInformation("节点列表成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("节点错误进入异常" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<FormDTO>>> GetCascadeForm([FromQuery] FormCasceQueryCommand command)
        {
            try
            {
                logger.LogInformation("表单级联成功");
                return mediator.Send(command);

            }
            catch (Exception ex)
            {
                logger.LogError("表单级联错误进入异常"+ex.Message);
                throw;
            }
        }


    }
}
